<template>
  <div class="card-container">
    <div class="card-img">
      <img :src="img" alt="">
    </div>
    <div class="content">
      <div class="card-time">
        <CalendarOutlined/>
        <span>发布于 {{ time }}</span>
      </div>
      <div class="card-title text-truncate">{{ title }}</div>
      <div class="card-interact">
                <span>
                    <svg class="icon" aria-hidden="true" width="16" height="16">
                        <use xlink:href="#icon-liulan"></use>
                    </svg>
                    <span>&nbsp;{{ cardData.viewCount }} 浏览</span>
                </span>&nbsp;&nbsp;
        <span>
                    <svg class="icon" aria-hidden="true" width="16" height="16">
                        <use xlink:href="#icon-pinglun"></use>
                    </svg>
                    <span>&nbsp;{{ cardData.commentCount }} 评论</span>
                </span>
      </div>
      <div class="card-tag">
        <div class="tag-item" v-for="(item, index) in tagList" :key="item.id">
          <svg v-if="index % 2 == 0" class="icon" aria-hidden="true" width="16" height="16">
            <use xlink:href="#icon-biaoqian1"></use>
          </svg>
          <svg v-if="index % 2 == 1" class="icon" aria-hidden="true" width="16" height="16">
            <use xlink:href="#icon-biaoqian"></use>
          </svg>
          &nbsp;
          <span>{{ item.tagName }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import {ref, reactive} from 'vue';
import {CalendarOutlined} from '@ant-design/icons-vue';

const props = defineProps({
  cardData: {
    type: Object,
    default: {},
  },
});
const {cardData} = props;

const img = ref(cardData.thumbnail);
const time = ref(cardData.createTime);
const title = ref(cardData.title);
const tagList = reactive(cardData.articleTagList)

</script>

<style scoped lang="less">
.card-container {
  // max-width: 1200px;
  width: 100%;
  height: 300px;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  transition: all 0.1s linear;
  cursor: pointer;

  &:hover {
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.6);
  }

  .card-img {
    overflow: hidden;
    height: 170px;
    display: flex;
    align-items: center;

    img {
      width: 100%;
      height: 100%;
      /* 图片不变形 */
      object-fit: cover;

      transition: all 0.8s ease;
      border-radius: 10px 10px 0 0;

      &:hover {
        transform: scale(1.3);
      }
    }
  }

  .content {
    padding: 5px 10px 10px 10px;

    .card-time {
      font-size: 12px;
      color: var(--text-color3);
    }

    .card-title {
      font-size: 20px;
      font-weight: bold;
      margin: 12px 0;
    }

    .card-interact {
      font-size: 12px;
      color: var(--text-color3);
      margin-bottom: 15px;
      display: flex;

      span:first-child,
      span:last-child {
        display: flex;
        align-items: center;
      }
    }

    .card-tag {
      display: flex;
      justify-content: left;
      align-items: center;

      .tag-item {
        font-size: 14px;
        border-radius: 5px;
        padding: 3px 5px;
        background-color: #eee;
        color: #9d9d9d;
        display: flex;
        align-items: center;
        transition: all 0.3s linear;

        &:hover {
          background-color: #ffa500;
          color: #fff;
        }
      }

      .tag-item {
        margin-right: 10px;
      }

      .tag-item:last-child {
        margin-right: 0;
      }
    }
  }

  .text-truncate {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 1;  /* 指定显示的行数 */
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.5;  /* 根据实际情况调整行高 */
    max-height: 1.5em;   /* 确保最大高度不超过2行 */
  }
}
</style>